// Created by Roman Novitsky on 03.04.2009


#region Imported Namespaces


using System.Diagnostics;

using WtfManager.Framework;
using WtfManager.UIManager.Commands;


#endregion


namespace WtfManager.FileManager
{
  /// <summary>
  /// Describes and manipulates a file open extension.
  /// </summary>
  public class FileOpenExtension: Service, IContentItemLauncherExtension
  {
    #region Properties/Indexers


    /// <summary>
    /// Gets a description of a component.
    /// </summary>
    public override string Description
    {
      get
      {
        return "An Open Command extension for opening files.";
      }
    }


    /// <summary>
    /// Gets a name of a component.
    /// </summary>
    public override string Name
    {
      get
      {
        return "File Open Extension";
      }
    }


    #endregion


    #region Methods


    protected override void OnStateChnaged()
    {
    }


    protected override FrameworkComponentState OnLoad()
    {
      return FrameworkComponentState.Loaded;
    }


    protected override void OnUnload()
    {
    }


    /// <summary>
    /// Determines whether this <see cref="IContentItemLauncherExtension"/> can launch the specified content item.
    /// </summary>
    /// <param name="contentItem">An instance of a <see cref="System.Object"/>.</param>
    /// <returns>
    /// 	<c>true</c> if this <see cref="IContentItemLauncherExtension"/> can launch the specified content item; otherwise, <c>false</c>.
    /// </returns>
    public bool CanLaunch(object contentItem)
    {
      Debug.Assert(IsInitialized, "FileOpenExtension was not yet initialized");

      return contentItem is FileSystemFile;
    }


    /// <summary>
    /// Launches the specified content item.
    /// </summary>
    /// <param name="contentItem">An instance of a <see cref="System.Object"/>.</param>
    public void Launch(object contentItem)
    {
      Debug.Assert(IsInitialized, "FileOpenExtension was not yet initialized");

      var file = (FileSystemFile)contentItem;
      file.Open();
    }


    protected override FrameworkComponentState OnInitialize()
    {
      return FrameworkComponentState.Initialized;
    }


    #endregion
  }
}